﻿@model SCMS.UI.Models.ViewTAForms
<div class="partialViewCard">
    <div class="partialViewCardHeader">
        <h3>
            N0.: @Model.TAuthFormEntity.RefNumber</h3>
    </div>
    @if (Model.CanApprove)
    {
        string linkText = null;
        string actionName = null;
        if (Model.TAuthFormEntity.IsReviewed && !Model.TAuthFormEntity.IsAuthorized && !Model.TAuthFormEntity.IsRejected)
        {
            linkText = "Authorize TAF";
            actionName = "LoadTAFForAuth";
        }
        else if (Model.TAuthFormEntity.IsSubmitted && !Model.TAuthFormEntity.IsReviewed && !Model.TAuthFormEntity.IsRejected)
        {
            linkText = "Review Travel Authorization";
            actionName = "ReviewTAF";
        }
        if (linkText != null)
        {
            <center>
                @Ajax.ActionLink(linkText, actionName, "RequestReview", new { id = "" }, new AjaxOptions
           {
               OnBegin = "ShowDialogueOR('" + linkText + ": " + Model.TAuthFormEntity.RefNumber + "')",
               UpdateTargetId = "popup-page",
               LoadingElementId = "popup-loading",
               Url = Url.Action(actionName + "/" + Model.TAuthFormEntity.Id, "RequestReview"),
               OnSuccess = "CenterPopup();calculateMBValue();"
           }) 
            </center>
        }
    }
    else
    {
        <br />
    }
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" class="cardTable">
        <tr class="gridheader">
            <th>
                Date
            </th>
            <th>
                Travellers Name
            </th>
            <th>
                Title
            </th>
        </tr>
        <tr>
            <td align="center">
                @Model.TAuthFormEntity.PreparedOn.Value.ToString("dd/MM/yyyy")
            </td>
            <td align="center">
                @if (Model.Travelller != null)
                {@Model.Travelller.StaffName}
                else
                { @Model.TAuthFormEntity.TravelerName}
            </td>
            <td align="center">
                @if (Model.Travelller != null)
                {@Model.Travelller.Designation}
                else
                { @Model.TAuthFormEntity.TravelerTitle}
            </td>
        </tr>
        <tr class="gridheader">
            <th align="center">
                Destination
            </th>
            <th align="center">
                Travell Type
            </th>
            <th align="center">
                Traveller Type
            </th>
        </tr>
        <tr>
            <td align="center">
                @Model.TAuthFormEntity.Destination
            </td>
            <td align="center">
                @Model.TAuthFormEntity.TravellType
            </td>
            <td align="center">
                @Model.TAuthFormEntity.TravellerType
            </td>
        </tr>
        <tr class="gridheader">
            <th align="center">
                Travel Start Date
            </th>
            <th align="center">
                Travel End Date
            </th>
            <th align="center">
                Total no. of nights
            </th>
        </tr>
        <tr>
            <td align="center">
                @Model.TAuthFormEntity.TravelStartDate.Value.ToString("dd/MM/yyyy")
            </td>
            <td align="center">
                @Model.TAuthFormEntity.TravelEndDate.Value.ToString("dd/MM/yyyy")
            </td>
            <td align="center">
                @Model.TAuthFormEntity.NoOfNights
            </td>
        </tr>
        <tr class="gridheader">
            <th align="center">
                Journey From
            </th>
            <th align="center">
                Journey To
            </th>
            <th align="center">
                Via
            </th>
        </tr>
        <tr>
            <td align="center">
                @Model.TAuthFormEntity.FromLocation
            </td>
            <td align="center">
                @Model.TAuthFormEntity.ToLocation
            </td>
            <td align="center">
                @Model.TAuthFormEntity.ViaLocation
            </td>
        </tr>
        <tr class="gridheader">
            <th align="center">
                Travel Means
            </th>
            <th align="left" colspan="2">
                TAF Currency
            </th>
        </tr>
        <tr>
            <td align="center">
                @Model.TAuthFormEntity.TravellMeans
            </td>
            <td align="left">
                @Model.TAuthFormEntity.Currency.ShortName
            </td>
        </tr>
        <tr>
            <th>
                Purpose of Travel:
            </th>
            <td colspan="2">@Model.TAuthFormEntity.TravelPurpose
            </td>
        </tr>
        <tr>
            <th>
                Remarks:
            </th>
            <td colspan="2">@Model.TAuthFormEntity.Remarks
            </td>
        </tr>
    </table>
    <br />
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" class="cardTable">
        <tr class="gridheader">
            <th style="width: 10%;">
                Travel Dates
            </th>
            <th style="width: 14%;">
                Destination
            </th>
            <th style="width: 10%;">
                No. Of Nights
            </th>
            <th style="width: 10%;">
                Per Diem/Daily Allowance Rate
            </th>
            <th style="width: 10%;">
                Total Allowance Rate
            </th>
            <th style="width: 10%;">
                Advance Required
            </th>
            <th style="width: 10%;">
                Currency
            </th>
            <th style="width: 12%;">
                Project No
            </th>
            <th style="width: 12%;">
                Budget Line
            </th>
        </tr>
        @foreach (var item in Model.TravelDates)
        {
            <tr>
                <td align="center">
                    @item.TravalDate.Value.ToString("dd/MM/yyyy")
                </td>
                <td>
                    @item.Destination
                </td>
                <td>
                    @item.NoOfNights
                </td>
                <td align="right">
                    @item.DailyPDRate.Value.ToString("##,##0.00")
                </td>
                <td align="right">
                    @item.TotalAllowance.Value.ToString("##,##0.00")
                </td>
                <td align="right">
                    @item.AdvanceRequired.Value.ToString("##,##0.00")
                </td>
                <td align="center">
                    @item.Currency.ShortName
                </td>
                <td align="center">
                    @item.ProjectBudget.BudgetCategory.ProjectDonor.ProjectNumber
                </td>
                <td align="center" title="@item.ProjectBudget.Description">
                    @item.ProjectBudget.LineNumber
                </td>
            </tr>
        }
    </table>
    <br />
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" class="cardTable">
        <tr class="gridheader">
            <th style="width: 34%;">
                Description of other anticipated Expenses
            </th>
            <th style="width: 14%;" colspan="2">
                Total cost of Expenses
            </th>
            <th style="width: 14%;">
                Advance Required
            </th>
            <th style="width: 12%;">
                Currency
            </th>
            <th style="width: 12%;">
                Project No
            </th>
            <th style="width: 12%;">
                Budget Line
            </th>
        </tr>
        @foreach (var item in Model.TravelExpenses)
        {
            <tr>
                <td>@item.ExpenseDescription
                </td>
                <td align="right" colspan="2">@item.TotalCost.Value.ToString("##,##0.00")
                </td>
                <td align="right">@item.AdvanceRequired.Value.ToString("##,##0.00")
                </td>
                <td align="center">
                    @item.Currency.ShortName
                </td>
                <td align="center">
                    @item.ProjectBudget.BudgetCategory.ProjectDonor.ProjectNumber
                </td>
                <td align="center" title="@item.ProjectBudget.Description">@item.ProjectBudget.LineNumber
                </td>
            </tr>
        }
        <tr>
            <th colspan="3" rowspan="2" class="gridheader" align="right">
                Total advance required for Per Diem/daily allowance & other anticipated expenses
            </th>
            <th align="center">
                Total Advance Required
            </th>
            <th class="gridheader" align="right">
                Currency
            </th>
            <th colspan="2" rowspan="2" class="gridheader">
            </th>
        </tr>
        <tr>
            <td align="right">
                @Model.TAuthFormEntity.TotalAmount.Value.ToString("#,##0.00")&nbsp;
            </td>
            <td align="center">
                @Model.TAuthFormEntity.Currency.ShortName
            </td>
        </tr>
        <tr>
            <td class="gridheader2" align="right">
                Master Budget Currency:&nbsp;
            </td>
            <td align="center">
                @Model.MBCurrency @if (!Model.TAuthFormEntity.MBCurrencyId.HasValue) { @Html.Raw("&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;") }
            </td>
            <td class="gridheader2" align="right">
                Total:&nbsp;
            </td>
            <td align="right">
                @if (Model.TAuthFormEntity.MBValue.HasValue) { @Model.TAuthFormEntity.MBValue.Value.ToString("#,##0.00")}
            </td>
            <td class="gridheader2" colspan="3">
                &nbsp;TAF Value
            </td>
        </tr>
    </table>
    <br />
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" class="cardTable">
        <tr class="gridheader">
            <td width="19%">
                Authorization
            </td>
            <td width="27%">
                TAF Request Prepared by
            </td>
            <td width="27%">
                Finance Review/Approval of BL/PN
            </td>
            <td width="27%">
                TAF Authorized by Manager/CD
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                Name:
            </td>
            <td>
                @Model.PreparedBy.StaffName
            </td>
            <td>
                @if (Model.ApprovedBy != null)
                {
                    @Model.ApprovedBy.StaffName
                }
            </td>
            <td>
                @if (Model.AuthorizedBy != null)
                {
                    @Model.AuthorizedBy.StaffName
                }
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                Title:
            </td>
            <td>
                @Model.PreparedBy.Designation;
            </td>
            <td>
                @if (Model.ApprovedBy != null)
                {
                    @Model.ApprovedBy.Designation
                }
            </td>
            <td>
                @if (Model.AuthorizedBy != null)
                {
                    @Model.AuthorizedBy.Designation
                }
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                Date:
            </td>
            <td>
                @Model.TAuthFormEntity.PreparedOn.Value.ToString("dd/MM/yyyy h:mm tt")
            </td>
            <td>
                @if (Model.ApprovedBy != null)
                {
                    @Model.TAuthFormEntity.ReviewedOn.Value.ToString("dd/MM/yyyy h:mm tt")
                }
            </td>
            <td>
                @if (Model.AuthorizedBy != null)
                {
                    @Model.TAuthFormEntity.AuthorizedOn.Value.ToString("dd/MM/yyyy h:mm tt")
                }
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                Signature:
            </td>
            <td>
                @if (Model.PreparedBy.SignatureImage != null)
                { 
                    <img src="@Url.Action("Photo", "Person", new { id = Model.PreparedBy.PersonID, area = "" })" alt="" style="max-width: 100px;" />
                }
            </td>
            <td>
                @if (Model.ApprovedBy != null && Model.ApprovedBy.SignatureImage != null)
                { 
                    <img src="@Url.Action("Photo", "Person", new { id = Model.PreparedBy.PersonID, area = "" })" alt="" style="max-width: 100px;" />
                }
            </td>
            <td>
                @if (Model.AuthorizedBy != null && Model.AuthorizedBy.SignatureImage != null)
                { 
                    <img src="@Url.Action("Photo", "Person", new { id = Model.AuthorizedBy.PersonID, area = "" })" alt="" style="max-width: 100px;" />
                }
            </td>
        </tr>
    </table>
    <hr />
    @if (Model.TAuthFormEntity.IsAuthorized == true)
    {

        <a class="btn btn-primary"  href="@Url.Action("Index", "TAF", new { area = "Reports", TAFid = Model.TAuthFormEntity.Id })" target="_blank" style="margin-left: 48%; margin-bottom: 2%;">
            Get PDF of TAF</a>
        <br />
    }
    @if (!Model.TAuthFormEntity.IsSubmitted)
    {
        
        <center>
            <input type="button" class="btn green" value="  Submit For Approval  " onclick="sendRequest('SubmitTAF/@Model.TAuthFormEntity.Id', 'ContentDiv', 'loading');if (document.getElementById('table') != null) {initSorter(); sorter.size(20); }" />
        </center>
    }
</div>
<p>
    @Html.ActionLink("Back to List", "Index")
</p>
